#ifndef _MY_MICRO_NUM_H_
#define _MY_MICRO_NUM_H_

#include "mytype.h"

#ifndef EXT_TRUE
#define EXT_TRUE 1
#define EXT_FALSE 0
#endif

#ifndef EXT_ENABLE
#define EXT_ENABLE 1
#define EXT_DISABLE 0
#endif

#define DIS 0
#define ENA 1
#define PRG 2

#define nKB(x) ((UU32)(x) << 10)
#define nMB(x) ((UU32)(x) << 20)
#define nGB(x) ((UU64)(x) << 30)
#define nTB(x) ((UU64)(x) << 40)
#define nPB(x) ((UU64)(x) << 50)
#define nEB(x) ((UU64)(x) << 60)
#define nZB(x) ((UU128)(x) << 70)
#define nYB(x) ((UU128)(x) << 80)

#define _KB_ ((UU32)(1) << 10)
#define _MB_ ((UU32)(1) << 20)
#define _GB_ ((UU32)(1) << 30)
#define _TB_ ((UU64)(1) << 40)
#define _PB_ ((UU64)(1) << 50)
#define _EB_ ((UU64)(1) << 60)
#define _ZB_ ((UU128)(1) << 70)
#define _YB_ ((UU128)(1) << 80)

#define LOG_TYPE_MASK 0x0F 
#define LOG_TYPE_HEAD 0x1  
#define LOG_TYPE_TAIL 0x3  
#define LOG_TYPE_DATA 0x2  
#define LOG_TYPE_EDIT 0x4  
#define LOG_TYPE_OPT 0x5   
#define LOG_TYPE_ALR 0x6   
#define LOG_TYPE_STAT 0x7  

#define LOG_FLAG_MASK 0xF0 
#define LOG_FLAG_NONE 0xF0

#define log_flag_type_make(flag, type) ((UU08)(((flag)&LOG_FLAG_MASK) | ((type)&LOG_TYPE_MASK)))
#define log_flag_make(flag) (~(UU08)((flag)&LOG_FLAG_MASK))
#define log_flag_get(fdat, flag) ((UU08)((~(fdat)) & (flag)&LOG_FLAG_MASK))
#define log_flag_merge(flag1, flag2) (~(UU08)((flag1) & (flag2)&LOG_FLAG_MASK))

#ifndef __kernel

#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t)(&((TYPE *)0)->MEMBER))
#endif

#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))

#define offsetofend(TYPE, MEMBER) \
	(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))

#ifndef SIZE_MAX
#define SIZE_MAX (~(size_t)0)
#endif

#define U8_MAX ((uu8)~0U)
#define S8_MAX ((ss8)(U8_MAX >> 1))
#define S8_MIN ((ss8)(-S8_MAX - 1))
#define U16_MAX ((uu16)~0U)
#define S16_MAX ((ss16)(U16_MAX >> 1))
#define S16_MIN ((ss16)(-S16_MAX - 1))
#define U32_MAX ((uu32)~0U)
#define U32_MIN ((uu32)0)
#define S32_MAX ((ss32)(U32_MAX >> 1))
#define S32_MIN ((ss32)(-S32_MAX - 1))
#define U64_MAX ((uu64)~0ULL)
#define S64_MAX ((ss64)(U64_MAX >> 1))
#define S64_MIN ((ss64)(-S64_MAX - 1))

#define USHRT_MAX ((unsigned short)~0U)
#define SHRT_MAX ((short)(USHRT_MAX >> 1))
#define SHRT_MIN ((short)(-SHRT_MAX - 1))
#define INT_MAX ((int)(~0U >> 1))
#define INT_MIN (-INT_MAX - 1)
#define UINT_MAX (~0U)
#define LONG_MAX ((long)(~0UL >> 1))
#define LONG_MIN (-LONG_MAX - 1)
#define ULONG_MAX (~0UL)
#define LLONG_MAX ((long long)(~0ULL >> 1))
#define LLONG_MIN (-LLONG_MAX - 1)
#define ULLONG_MAX (~0ULL)

#define is_power_of_2(n) (n != 0 && ((n & (n - 1)) == 0))
	extern const char hex_asc[];
#define hex_asc_lo(x) hex_asc[((x)&0x0f)]
#define hex_asc_hi(x) hex_asc[((x)&0xf0) >> 4]

#endif

#endif 
